package com.spring.MyBatis.dao;

import com.spring.MyBatis.domain.ProductBean;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Map;

public interface ProductBeanMapper {
    //这是自动生成的
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table product
     *
     * @mbg.generated Fri Oct 08 08:32:13 CST 2021
     */
    @Delete({
        "delete from product",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table product
     *
     * @mbg.generated Fri Oct 08 08:32:13 CST 2021
     */
    @Insert({
        "insert into product (id, product_name, ",
        "price, product_desc)",
        "values (#{id,jdbcType=INTEGER}, #{productName,jdbcType=VARCHAR}, ",
        "#{price,jdbcType=INTEGER}, #{productDesc,jdbcType=VARCHAR})"
    })
    int insert(ProductBean record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table product
     *
     * @mbg.generated Fri Oct 08 08:32:13 CST 2021
     */
    @InsertProvider(type=ProductBeanSqlProvider.class, method="insertSelective")
    int insertSelective(ProductBean record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table product
     *
     * @mbg.generated Fri Oct 08 08:32:13 CST 2021
     */
    @Select({
        "select",
        "id, product_name, price, product_desc",
        "from product",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="product_name", property="productName", jdbcType=JdbcType.VARCHAR),
        @Result(column="price", property="price", jdbcType=JdbcType.INTEGER),
        @Result(column="product_desc", property="productDesc", jdbcType=JdbcType.VARCHAR)
    })
    ProductBean selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table product
     *
     * @mbg.generated Fri Oct 08 08:32:13 CST 2021
     */
    @UpdateProvider(type=ProductBeanSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(ProductBean record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table product
     *
     * @mbg.generated Fri Oct 08 08:32:13 CST 2021
     */
    @Update({
        "update product",
        "set product_name = #{productName,jdbcType=VARCHAR},",
          "price = #{price,jdbcType=INTEGER},",
          "product_desc = #{productDesc,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ProductBean record);


    @Select("select * from product")  //映射器类必须是一个接口，而不是具体的实现类。在这个示例中，通过注解来指定 SQL 语句
    public List<Map<String,Object>> query();
}